# [例一]
class MyList(list):
    pass


lst = MyList([1, 2, 3, 4, 5])
lst.append(90)
lst.sort()
print(lst)  # [1, 2, 3, 4, 5, 90]


# [例子]
# 类定义
class People:
    # 定义基本属性
    name = ''
    age = 0
    # 定义私有属性，私有属性在外部无法直接进行访问
    __weight = 0

    # 定义构造方法
    def __init__(self, name, age, weight):
        self.name = name
        self.age = age
        self.__weight = weight

    def speak(self):
        print("%s 说我 %s 岁。") % (self.name, self.age)


class student(People):
    grade = ''

    def __init__(self, name, age, weight, grade):
        People.__init__(self, name, age, weight)
        self.grade = grade

    def speak(self):
        print("%s 说我 %s 岁, 在读%s年纪。" % (self.name, self.age, self.grade))


s = student('小马的程序人生', 10, 60, 3)
s.speak()

# [例三]
import random


class Fish:
    def __init__(self):
        self.x = random.randint(0, 10)
        self.y = random.randint(0, 10)

    def move(self):
        self.x -= 1  # 向左移动
        print("我的位置", self.x, self.y)


class GoldFish(Fish):  # 金鱼
    pass


class Carp(Fish):  # 鲤鱼
    pass


class Shark(Fish):
    def __init__(self):
        self.hungry = True

    def eat(self):
        if self.hungry:
            print("吃货的梦想就是天天有得吃！")
            self.hungry = False
        else:
            print("太撑了，吃不下了！")
            self.hungry = True


g = GoldFish()
g.move()  # 我的位置 9 5
s = Shark()
s.eat()  # 吃货的梦想就是天天有得吃！
s.move()  # AttributeError: 'Shark' object has no attribute 'x'
